use optimized powf for x^(1.0/2.4)
authorØyvind Kolås <pippin@gimp.org>
Sat, 31 Mar 2012 02:47:06 +0000 (03:47 +0100)
committerØyvind Kolås <pippin@gimp.org>
Sat, 31 Mar 2012 02:47:06 +0000 (03:47 +0100)
babl/base/util.h

index 7ccaf8f56420538e996b04cf4b58e293f680aec8..bca25ebac866f8efa33d718fec220f049b2860eb 100644 (file)
 
 #ifdef BABL_USE_SRGB_GAMMA
 
+/*  fast approximation of x ^ (5/12) from a response by David Hammen at
+ *  http://stackoverflow.com/questions/6475373/optimizations-for-pow-with-const-non-integer-exponent/6475516#6475516
+ *
+ */
+static inline double xpow512 (double x)
+{
+  double cbrtx = cbrt(x);
+  return cbrtx*sqrt(sqrt(cbrtx));
+}
+
+
 static inline double
 linear_to_gamma_2_2 (double value)
 {
+#if 0
   if (value > 0.0030402477F)
     return 1.055F * pow (value, (1.0F/2.4F)) - 0.055F;
   return 12.92F * value;
+#else
+  if (value > 0.0030402477F)
+    return 1.055F * xpow512 (value) - 0.055F;
+  return 12.92F * value;
+#endif
 }
 
 static inline double